package Ctr;

import DB.DBCustomer;
import Model.Customer;

/**
 * @author Anders
 *
 */
public class CtrCustomer 
{
	private DBCustomer dbc;
	public enum UPDATE{UPDATE_SUCCESS, UPDATE_DELETE_FAILED, UPDATE_ADD_FAILED};
	
	public CtrCustomer()
	{
		dbc = new DBCustomer();
	}
	
	public boolean addCustomer(String name, String address, String zipCode, String city, String phoneNo)
	{
		int i = Integer.parseInt(dbc.getHighestID()) + 1;
		String HighNo = Integer.toString(i);
		return dbc.addCustomer(new Customer(HighNo, name, address, zipCode, city, phoneNo));
	}
	
	public boolean deleteCustomer(String id)
	{
		return dbc.deleteCustomer(id);
	}
	
	public Customer getCustomer(String phoneNo)
	{
		return dbc.getCustomer(phoneNo);
	}
	
	public void updateCustomer(String id, String name, String address, String zipCode, String city, String phoneNo)
	{
		/* OLD return UPDATE not void
		if(deleteCustomer(id)) {
			if(addCustomer(name, address, zipCode, city, phoneNo)) {
				return UPDATE.UPDATE_SUCCESS;
			}
			else {
				return UPDATE.UPDATE_ADD_FAILED;
			}
		}
		else {
			return UPDATE.UPDATE_DELETE_FAILED;
		}
		*/
		
		dbc.updateCustomer(id, name, address, zipCode, city, phoneNo);
	}
}
